<template>
  <div class="wx-open-subscribe-container" style="position:absolute;width:100%;height:100%;top:0px;">
    <wx-open-subscribe :template="templateId" id="subscribe-btn" style="position:absolute;width:100%;height:100%;left:0px;top:0px;overflow:hidden;">
      <script type="text/wxtag-template">
        <style>.btn { width: 100%; height: 500px;}</style>
        <div class="btn"></div>
      </script>
    </wx-open-subscribe>
  </div>
</template>
<script>
export default {
  props: {
    templateId: {
      type: String,
      default() {
        return ''
      }
    }
  },
  mounted() {
    const vm = this
    let subscribebtn = document.getElementById('subscribe-btn');
    subscribebtn.addEventListener('success', function (e) { 
      let jsonStr = e.detail.subscribeDetails.replace(" ", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          let jj = JSON.parse(jsonStr);
          vm.$emit('open-subscribe-success', jj)
        }
    })
  },
  methods: {

  }
}
</script>

